package com.dz.control;

import com.dz.bean.DingDanBean;
import com.dz.dao.DingDanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class DingDanController {

    @Autowired
    DingDanMapper dingDanMapper;

    //查询数据库中t_order表中的所有数据，返回给前端页面；
    @RequestMapping("/selectList")
    public String list(Model model){
        List<DingDanBean> dingDanBeans = dingDanMapper.queryOrderList();
        //放在请求中
        model.addAttribute("orders",dingDanBeans);
        return "/order-list";
    }
    //向表中插入数据；
    @RequestMapping("/toInsert")
    public String toAdd(DingDanBean dingDanBean){
        dingDanMapper.insertOrder(dingDanBean);
        return "redirect:/selectList";
    }

    //修改表中的数据；
    @RequestMapping("/toUpdate")
    public String toUpdate(DingDanBean dingDanBean){
        dingDanMapper.updateByOrderNumber(dingDanBean);
        return "redirect:/selectList";
    }

    //删除表中的某条数据；
    @RequestMapping("/toDelete/{orderNumber}")
    public String toDelete(@PathVariable("orderNumber") String orderNumber){
        dingDanMapper.deleteByOrderNumber(orderNumber);
        return "redirect:/selectList";
    }

    //跳转到order-add.html
    @RequestMapping("/toAdd")
    public String toAdd(){
        return "order-add";
    }


}
